package me.zhengjie.modules.fileupload.utils;

import me.zhengjie.utils.StringUtils;

import java.util.UUID;

public class FileUtils {

    /**
     * 获取文件扩展名
     */
    public static String getFileExtension(String fileName) {
        if (fileName == null) {
            return "";
        }
        int dotIndex = fileName.lastIndexOf('.');
        return (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1);
    }

    /**
     * 生成唯一文件名
     */
    public static String generateUniqueFileName(String originalFileName) {
        String extension = getFileExtension(originalFileName);
        return UUID.randomUUID().toString() + (StringUtils.isNotEmpty(extension) ? "." + extension : "");
    }
}
